package com.yssw.store.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.yssw.common.utils.DateUtils;
import com.yssw.model.vo.store.StoreVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yssw.store.mapper.DistributionStoreMapper;
import com.yssw.store.domain.DistributionStore;
import com.yssw.store.service.IDistributionStoreService;

/**
 * 门店分布城市Service业务层处理
 *
 * @author yssw
 * @date 2023-03-28
 */
@Service
public class DistributionStoreServiceImpl implements IDistributionStoreService {
    @Autowired
    private DistributionStoreMapper distributionStoreMapper;

    /**
     * 查询门店分布城市
     *
     * @param id 门店分布城市主键
     * @return 门店分布城市
     */
    @Override
    public DistributionStore selectDistributionStoreById(Long id) {
        return distributionStoreMapper.selectDistributionStoreById(id);
    }

    /**
     * 查询门店分布城市列表
     *
     * @param distributionStore 门店分布城市
     * @return 门店分布城市
     */
    @Override
    public List<DistributionStore> selectDistributionStoreList(DistributionStore distributionStore) {

        return distributionStoreMapper.selectDistributionStoreList(distributionStore);
    }

    @Override
    public List<StoreVo> selectStoreGroupList() {
        List<StoreVo> storeVoList = new ArrayList<>();
        List<String> strings = distributionStoreMapper.selectDistributionStoreGroup();
        strings.forEach(s -> {
            DistributionStore distributionStore = new DistributionStore();
            distributionStore.setDistributionCity(s);
            List<DistributionStore> distributionStores = distributionStoreMapper.selectDistributionStoreList(distributionStore);
            StoreVo storeVo = new StoreVo();
            storeVo.setCityName(s);
            storeVo.setStoreList(distributionStores);
            storeVoList.add(storeVo);
        });
        return storeVoList;
    }

    /**
     * 新增门店分布城市
     *
     * @param distributionStore 门店分布城市
     * @return 结果
     */
    @Override
    public int insertDistributionStore(DistributionStore distributionStore) {
        distributionStore.setCreateTime(DateUtils.getNowDate());
        return distributionStoreMapper.insertDistributionStore(distributionStore);
    }

    /**
     * 修改门店分布城市
     *
     * @param distributionStore 门店分布城市
     * @return 结果
     */
    @Override
    public int updateDistributionStore(DistributionStore distributionStore) {
        distributionStore.setUpdateTime(DateUtils.getNowDate());
        return distributionStoreMapper.updateDistributionStore(distributionStore);
    }

    /**
     * 批量删除门店分布城市
     *
     * @param ids 需要删除的门店分布城市主键
     * @return 结果
     */
    @Override
    public int deleteDistributionStoreByIds(Long[] ids) {
        return distributionStoreMapper.deleteDistributionStoreByIds(ids);
    }

    /**
     * 删除门店分布城市信息
     *
     * @param id 门店分布城市主键
     * @return 结果
     */
    @Override
    public int deleteDistributionStoreById(Long id) {
        return distributionStoreMapper.deleteDistributionStoreById(id);
    }
}
